import { axios } from '@/utils/request'

const api = {
  hospitals: '/hospitals'
}

export function getHospital () {
  return axios({
    url: api.hospitals,
    method: 'GET'
  })
}

// 根据用户 name 获取医院信息
export function getHospitals (name) {
  return axios({
    url: `${api.hospitals}?name=${name}`,
    method: 'GET'
  })
}

// 根据用户 id 获取医院信息
export function getHospitalById (id) {
  return axios({
    url: `${api.hospitals}/${id}`,
    method: 'GET'
  })
}

// 添加医院信息
export function addHospital (parameter) {
  return axios({
    url: api.hospitals,
    method: 'POST',
    data: parameter
  })
}

// 修改医院信息
export function changeHospital (parameter) {
  return axios({
    url: `${api.hospitals}/${parameter.id}`,
    method: 'PUT',
    data: parameter
  })
}

// 删除医院信息
export function deleteHospital (hospitalId) {
  return axios({
    url: `${api.hospitals}/${hospitalId}`,
    method: 'DELETE'
  })
}

// 添加物资需求信息
export function addDemand (parameter) {
  return axios({
    url: `${api.hospitals}/${parameter.hospitalId}/` + 'medical-supplies',
    method: 'POST',
    data: parameter
  })
}

// 根据id查询需求信息
export function getDemandById (hospitalId, id) {
  return axios({
    url: `${api.hospitals}/${hospitalId}/` + 'medical-supplies/' + id,
    method: 'GET'
  })
}

// 删除物资需求信息
export function deleteDemand (hospitalId, id) {
  return axios({
    url: `${api.hospitals}/${hospitalId}/` + 'medical-supplies/' + id,
    method: 'DELETE'
  })
}

// 修改物资需求信息
export function changeDemand (parameter) {
  return axios({
    url: `${api.hospitals}/${parameter.hospitalId}/` + 'medical-supplies/' + parameter.id,
    method: 'PUT',
    data: parameter
  })
}

// 根据id查询联系人信息
export function getContactById (hospitalId, id) {
  return axios({
    url: `${api.hospitals}/${hospitalId}/` + 'contacts/' + id,
    method: 'GET'
  })
}

// 添加联系人信息
export function addContact (parameter) {
  return axios({
    url: `${api.hospitals}/${parameter.hospitalId}/` + 'contacts',
    method: 'POST',
    data: parameter
  })
}

// 修改联系人信息
export function changeContact (parameter) {
  return axios({
    url: `${api.hospitals}/${parameter.hospitalId}/contacts/${parameter.id}`,
    method: 'PUT',
    data: parameter
  })
}

// 删除联系人信息
export function deleteContact (hospitalId, id) {
  return axios({
    url: `${api.hospitals}/${hospitalId}/` + 'contacts/' + id,
    method: 'DELETE'
  })
}
